package com.quick.mybatis.utils;

public final class DoubleUtil {

	public static Double parse(Object o) {
		if (o == null || o.equals(""))
			return null;

		Class<? extends Object> clazz = o.getClass();
		if (clazz.equals(Double.class) || clazz.equals(double.class)) {
			return (Double) o;
		}

		try {
			String v = String.valueOf(o);
			boolean isPercent = v.endsWith("%");
			if (isPercent) {
				v = v.substring(0, v.length() - 1);
			}

			Double d = Double.valueOf(v);
			if (isPercent) {
				d = d / 100;
			}

			return d;

		} catch (Exception e) {
			return 0d;
		}
	}
}
